package com.lz.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by lz on 2018/5/21.
 */
@Repository
public class HomeDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 通过期限查询快速投资
     */
    public List<Map<String, Object>> queryPeriod(String start, String end) {

        String sql = "SELECT * , concat(TRUNCATE( minInterestRatePerYear * 100,2),'%') as syl " +
                " FROM `regular` WHERE investPeriod > ? AND investPeriod < ? " +
                " ORDER BY minInterestRatePerYear DESC limit 0,20";
        return jdbcTemplate.queryForList(sql, start, end);

    }

    /**
     * 测试题推荐产品
     * @param level
     * @param pageIndex
     * @param pageSize
     */
    public List<Map<String, Object>> recommend(String level, String pageIndex, String pageSize) {
        String sql = " select * from regular where riskLevel = ? ORDER BY minInterestRatePerYear DESC limit ?,? ";
        return jdbcTemplate.queryForList(sql, level,Integer.parseInt(pageIndex),Integer.parseInt(pageSize));
    }

    /**
     * 查询定期数量
     * @return
     */
    public Map<String, Object> queryNum(){
        String sql = "select count(*) as amount from  regular";
        return jdbcTemplate.queryForMap(sql);
    }
}
